//
//  ZHBUpLoadManager.m
//  SelectPhotosOrVideoContentViewLib
//
//  Created by Dubaoquan on 2019/1/11.
//

#import "ZHBUpLoadManager.h"
#import <QiniuSDK.h>
#import "UploadProgressView.h"
#import "HJNetwork.h"
#import "AppConst.h"
#import "ProjectMediator+LoginAndRegisterLib.h"

@interface ZHBUpLoadManager()
@property (nonatomic,strong) NSString *tokenType;
@property (nonatomic,strong) NSString *qiniuToken;
@property (nonatomic,strong) QNUploadManager *qiNiumanager;
@property (nonatomic,assign) NSInteger imageCount;
@property (nonatomic,strong) NSMutableArray *imageUploadPerscentArr;
@end

@implementation ZHBUpLoadManager

+(instancetype)sharedInstance{
    __strong static ZHBUpLoadManager *sharedManager;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedManager = [[ZHBUpLoadManager alloc] init];
    });
    return sharedManager;
}
-(instancetype)init{
    self  = [super init];
    if (self) {
    }
    return self;
}
-(void)prepareWithTokenType:(NSString*)tokenType{
    self.tokenType = tokenType;
    WEAK_SELF(weakSelf)
    LoginDataManager *loginDataManager = [[ProjectMediator sharedInstance] getLoginDataManagerInLoginAndRegisterLib];
    [HJNetwork setHeadr:@{@"Accept":@"application/vnd.zhb.v1+json"}];
    [HJNetwork setHeadr:@{@"Authorization":[NSString stringWithFormat:@"Bearer %@",loginDataManager.currentLoginData.token]}];
    [HJNetwork HTTPWithMethod:HJRequestMethodGET url:[NSString stringWithFormat:@"%@api/app/qiniu/token",ServerNewIP] parameters:@{@"type":tokenType} cachePolicy:HJCachePolicyIgnoreCache callback:^(id responseObject, BOOL isCache, NSError *error) {
        STRONG_SELF(strongSelf)
        if (responseObject!=nil) {
            
            strongSelf.qiniuToken = responseObject[@"token"];
            
        }else{
            
            NSLog(@"获取七牛云上传凭证失败");
            
        }
    }];
    
}
/*
 asset:即使是手动拍摄的视频也是存入相册后选取的，所以视频都是PHAsset类型的
 videoKey: 上传成功后的视频文件名关联的发布接口文档提供的key
 videoName：用于判断视频的格式
 coverImage：视频封面图片
 coverImageFileNameKey：图片的路径名称，用于后台识判断别是哪个业务上传过来的图片
 coverImagePostKeyName：发布接口文档提供的用于关联上传成功的封面图片信息的key
 postURLStr：视频发布接口地址
 parameters：视频发布接口参数
 notificationName：发布成功后用于通知注册了这个通知的所有对象做下一步动作
 */
-(void)uploadVideoWith:(PHAsset *)asset  videoKey:(NSString*)videoKey videoName:(NSString*)videoName coverImage:(UIImage*)coverImage coverImageFileNameKey:(NSString*)coverImageFileNameKey coverImagePostKeyName:(NSString*)coverImagePostKeyName videoPath:(NSString*)videoPath postURL:(NSString*)postURLStr parameters:(NSDictionary*)parameters notificationName:(NSString*)notificationName{
    self.releaseSuccessedNotificationName = notificationName;
    __block NSMutableDictionary *mutableParameters = [NSMutableDictionary dictionaryWithDictionary:parameters];
    if (self.qiniuToken.length==0) {
        [self prepareWithTokenType:self.tokenType];
        return;
    }
    if (asset.mediaType == PHAssetMediaTypeVideo) {
        WEAK_SELF(weakSelf)
        
        
        QNUploadOption *uploadOption = [[QNUploadOption alloc]initWithProgressHandler:^(NSString *key, float percent) {
            dispatch_async(dispatch_get_main_queue(), ^{
                [[UploadProgressView sharedInstance] showWithTitle:[NSString stringWithFormat:@"封面%.0f%%",percent*100] progress:percent];
            });
            
        }];
        //视频封面上传
        NSData *coverImageData = UIImageJPEGRepresentation(coverImage,0.83);
        [self.qiNiumanager putData:coverImageData key:[NSString stringWithFormat:@"%@%@.jpg",coverImageFileNameKey,[self generateRandomFileName]] token:self.qiniuToken complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
            
            if (info.error==nil) {
                NSDictionary *imageInfo = @{@"path":key,@"width":@(coverImage.size.width*[UIScreen mainScreen].scale),@"height":@(coverImage.size.height*[UIScreen mainScreen].scale)};
                NSData *data=[NSJSONSerialization dataWithJSONObject:imageInfo options:NSJSONWritingPrettyPrinted error:nil];
                NSString *jsonStr=[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
                [mutableParameters setObject:jsonStr forKey:coverImagePostKeyName];
            }
            //开始上传视频
            PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
            options.version = PHImageRequestOptionsVersionCurrent;
            options.deliveryMode = PHVideoRequestOptionsDeliveryModeAutomatic;
            options.networkAccessAllowed = YES;
            options.progressHandler = ^(double progress, NSError * _Nullable error, BOOL * _Nonnull stop, NSDictionary * _Nullable info) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    [[UploadProgressView sharedInstance] showWithTitle:[NSString stringWithFormat:@"同步%.0f%%",progress*100] progress:progress];
                });
            };
            //获取视频数据
            PHImageManager *manager = [PHImageManager defaultManager];
            [manager requestAVAssetForVideo:asset options:options resultHandler:^(AVAsset * _Nullable asset, AVAudioMix * _Nullable audioMix, NSDictionary * _Nullable info) {
                if(![asset isKindOfClass:[AVURLAsset class]]){
                    return;
                }
                STRONG_SELF(strongSelf)
                AVURLAsset *urlAsset = (AVURLAsset *)asset;
                NSURL *url = urlAsset.URL;
                NSData *data = [NSData dataWithContentsOfURL:url];
                NSArray *arr = [videoName componentsSeparatedByString:@"."];
                NSString *type = @"mp4";
                if(arr.count>1){
                    type = arr.lastObject;
                }
                QNUploadOption *uploadOption = [[QNUploadOption alloc]initWithProgressHandler:^(NSString *key, float percent) {
                    dispatch_async(dispatch_get_main_queue(), ^{
                        [[UploadProgressView sharedInstance] showWithTitle:[NSString stringWithFormat:@"视频%.0f%%",percent*100] progress:percent];
                    });
                    
                }];
                //上传视频
                [strongSelf.qiNiumanager putData:data key:[NSString stringWithFormat:@"%@%@.%@",videoPath,[self generateRandomFileName],type] token:self.qiniuToken complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
                    
                    if (info.error==nil) {//视频上传七牛成功，开始执行发布接口
                        [mutableParameters setObject:key forKey:videoKey];
                        LoginDataManager *loginDataManager = [[ProjectMediator sharedInstance] getLoginDataManagerInLoginAndRegisterLib];
                        [HJNetwork setHeadr:@{@"Accept":@"application/vnd.zhb.v1+json"}];
                        [HJNetwork setHeadr:@{@"Authorization":[NSString stringWithFormat:@"Bearer %@",loginDataManager.currentLoginData.token]}];
                        [HJNetwork HTTPWithMethod:HJRequestMethodPOST url:postURLStr parameters:mutableParameters cachePolicy:HJCachePolicyIgnoreCache callback:^(id responseObject, BOOL isCache, NSError *error) {
                            
                            if (error==nil) {
                                
                                [[UploadProgressView sharedInstance] hideWithTitle:@"发布成功！"];
                                dispatch_async(dispatch_get_main_queue(), ^{
                                    [[NSNotificationCenter defaultCenter] postNotificationName:strongSelf.releaseSuccessedNotificationName object:responseObject];
                                });
                            }else{
                                [[UploadProgressView sharedInstance] hideWithTitle:@"发布失败！"];
                                NSLog(@"发布失败");
                                
                            }
                        }];
                        
                    }else{
                        
                    }
                } option:uploadOption];
            }];
            
        } option:uploadOption];
        
    }
}
-(void)uploadImageWith:(NSArray<UIImage *>*)imageDataArr imagefileNameKey:(NSString*)imagefileNameKey  imagePostKeyName:(NSString*)imagePostKeyName postURL:(NSString*)postURLStr parameters:(NSDictionary*)parameters  notificationName:(NSString*)notificationName{
    self.releaseSuccessedNotificationName = notificationName;
    self.imageCount = imageDataArr.count;
    self.imageUploadPerscentArr = [NSMutableArray arrayWithCapacity:self.imageCount];
    for (NSInteger i=0; i<self.imageCount; i++) {
        [self.imageUploadPerscentArr addObject:@(0.0)];
    }
    
    __block NSMutableDictionary *mutableParameters = [NSMutableDictionary dictionaryWithDictionary:parameters];
    __block NSMutableArray *images = [NSMutableArray array];
    
    dispatch_group_t group = dispatch_group_create();
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    WEAK_SELF(weakSelf)
    
    for (UIImage *image in imageDataArr) {
        
        dispatch_group_enter(group);
        
        dispatch_async(queue, ^{
            STRONG_SELF(strongSelf)
            
            QNUploadOption *uploadOption = [[QNUploadOption alloc]initWithProgressHandler:^(NSString *key, float percent) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    [strongSelf.imageUploadPerscentArr replaceObjectAtIndex:[imageDataArr indexOfObject:image] withObject:@(percent/strongSelf.imageCount*100)];
                    CGFloat percent = 0.0;
                    for (NSNumber *percentValue in strongSelf.imageUploadPerscentArr) {
                        percent += percentValue.floatValue;
                    }
                    [[UploadProgressView sharedInstance] showWithTitle:[NSString stringWithFormat:@"图片%.0f%%",percent] progress:percent];
                });
                
            }];
            
            NSData *imageData=UIImageJPEGRepresentation(image,0.83);
            [strongSelf.qiNiumanager putData:imageData key:[NSString stringWithFormat:@"%@%@.jpg",imagefileNameKey,[strongSelf generateRandomFileName]] token:strongSelf.qiniuToken complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
                
                if (info.error==nil) {
                    [images addObject:@{@"path":key,@"width":@(image.size.width*[UIScreen mainScreen].scale),@"height":@(image.size.height*[UIScreen mainScreen].scale)}];
                    
                }else{
                    
                }
                dispatch_group_leave(group);
            } option:uploadOption];
            
            
        });
    }
    
    dispatch_group_notify(group, queue, ^{//所有图片上传完成
        
        NSData *data=[NSJSONSerialization dataWithJSONObject:images options:NSJSONWritingPrettyPrinted error:nil];
        NSString *jsonStr=[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
        [mutableParameters setObject:jsonStr forKey:imagePostKeyName];
        STRONG_SELF(strongSelf)
        LoginDataManager *loginDataManager = [[ProjectMediator sharedInstance] getLoginDataManagerInLoginAndRegisterLib];
        [HJNetwork setHeadr:@{@"Accept":@"application/vnd.zhb.v1+json"}];
        [HJNetwork setHeadr:@{@"Authorization":[NSString stringWithFormat:@"Bearer %@",loginDataManager.currentLoginData.token]}];
        [HJNetwork HTTPWithMethod:HJRequestMethodPOST url:postURLStr parameters:mutableParameters cachePolicy:HJCachePolicyIgnoreCache callback:^(id responseObject, BOOL isCache, NSError *error) {
            
            if (error==nil) {
                
                [[UploadProgressView sharedInstance] hideWithTitle:@"发布成功！"];
                
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    
                    [[NSNotificationCenter defaultCenter] postNotificationName:strongSelf.releaseSuccessedNotificationName object:nil];
                    
                });
            }else{
                [[UploadProgressView sharedInstance] hideWithTitle:@"发布失败！"];
                NSLog(@"发布失败");
                
            }
        }];
    });
    
}

-(void)uploadImagesWith:(NSArray<UIImage *>*)imageDataArr imagefileNOPathNameKey:(NSString*)imagefileNameKey  imagePostKeyName:(NSString*)imagePostKeyName postURL:(NSString*)postURLStr parameters:(NSDictionary*)parameters  notificationName:(NSString*)notificationName{
    self.releaseSuccessedNotificationName = notificationName;
    self.imageCount = imageDataArr.count;
    self.imageUploadPerscentArr = [NSMutableArray arrayWithCapacity:self.imageCount];
    for (NSInteger i=0; i<self.imageCount; i++) {
        [self.imageUploadPerscentArr addObject:@(0.0)];
    }
    
    __block NSMutableDictionary *mutableParameters = [NSMutableDictionary dictionaryWithDictionary:parameters];
    __block NSMutableArray *images = [NSMutableArray array];
    
    dispatch_group_t group = dispatch_group_create();
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    WEAK_SELF(weakSelf)
    
    for (UIImage *image in imageDataArr) {
        
        dispatch_group_enter(group);
        
        dispatch_async(queue, ^{
            STRONG_SELF(strongSelf)
            
            QNUploadOption *uploadOption = [[QNUploadOption alloc]initWithProgressHandler:^(NSString *key, float percent) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    [strongSelf.imageUploadPerscentArr replaceObjectAtIndex:[imageDataArr indexOfObject:image] withObject:@(percent/strongSelf.imageCount*100)];
                    CGFloat percent = 0.0;
                    for (NSNumber *percentValue in strongSelf.imageUploadPerscentArr) {
                        percent += percentValue.floatValue;
                    }
                    [[UploadProgressView sharedInstance] showWithTitle:[NSString stringWithFormat:@"图片%.0f%%",percent] progress:percent];
                });
                
            }];
            
            NSData *imageData=UIImageJPEGRepresentation(image,0.83);
            [strongSelf.qiNiumanager putData:imageData key:[NSString stringWithFormat:@"%@%@.jpg",imagefileNameKey,[strongSelf generateRandomFileName]] token:strongSelf.qiniuToken complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
                
                if (info.error==nil) {
                    [images addObject:key];
                    
                }else{
                    
                }
                dispatch_group_leave(group);
            } option:uploadOption];
            
            
        });
    }
    
    dispatch_group_notify(group, queue, ^{//所有图片上传完成

        [mutableParameters setObject:images forKey:imagePostKeyName];
        STRONG_SELF(strongSelf)
        LoginDataManager *loginDataManager = [[ProjectMediator sharedInstance] getLoginDataManagerInLoginAndRegisterLib];
        [HJNetwork setHeadr:@{@"Accept":@"application/vnd.zhb.v1+json"}];
        [HJNetwork setHeadr:@{@"Authorization":[NSString stringWithFormat:@"Bearer %@",loginDataManager.currentLoginData.token]}];
        [HJNetwork HTTPWithMethod:HJRequestMethodPOST url:postURLStr parameters:mutableParameters cachePolicy:HJCachePolicyIgnoreCache callback:^(id responseObject, BOOL isCache, NSError *error) {
            
            if (error==nil) {
                
                [[UploadProgressView sharedInstance] hideWithTitle:@"发布成功！"];
                
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    
                    [[NSNotificationCenter defaultCenter] postNotificationName:strongSelf.releaseSuccessedNotificationName object:nil];
                    
                });
            }else{
                
                NSLog(@"发布失败");
                if (error) {
                    NSData *errorData = error.userInfo[@"com.alamofire.serialization.response.error.data"];
                    
                    NSDictionary *serializedData = [NSJSONSerialization JSONObjectWithData: errorData options:kNilOptions error:nil];
                    NSString *message;
                    if (serializedData[@"message"]) {
                        message = [NSString stringWithFormat:@"%@",serializedData[@"message"]];
                    }else{
                        message = @"发布失败";
                    }
                    
                    [[UploadProgressView sharedInstance] hideWithTitle:message];
                }
            }
        }];
    });
    
}

-(void)uploadImagesWith:(NSArray<UIImage *>*)imageDataArr
 imagefileNOPathNameKey:(NSString*)imagefileNameKey
            andImgBlock:(UpImgsRequest)imgPathsBlock{
                self.imageCount = imageDataArr.count;
                self.imageUploadPerscentArr = [NSMutableArray arrayWithCapacity:self.imageCount];
                for (NSInteger i=0; i<self.imageCount; i++) {
                    [self.imageUploadPerscentArr addObject:@(0.0)];
                }
                
                __block NSMutableArray *images = [NSMutableArray array];
                
                dispatch_group_t group = dispatch_group_create();
                dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
                WEAK_SELF(weakSelf)
                
                for (UIImage *image in imageDataArr) {
                    
                    dispatch_group_enter(group);
                    
                    dispatch_async(queue, ^{
                        STRONG_SELF(strongSelf)
                        
                        QNUploadOption *uploadOption = [[QNUploadOption alloc]initWithProgressHandler:^(NSString *key, float percent) {
                            dispatch_async(dispatch_get_main_queue(), ^{
                                [strongSelf.imageUploadPerscentArr replaceObjectAtIndex:[imageDataArr indexOfObject:image] withObject:@(percent/strongSelf.imageCount*100)];
                                CGFloat percent = 0.0;
                                for (NSNumber *percentValue in strongSelf.imageUploadPerscentArr) {
                                    percent += percentValue.floatValue;
                                }
                                [[UploadProgressView sharedInstance] showWithTitle:[NSString stringWithFormat:@"图片%.0f%%",percent] progress:percent];
                            });
                            
                        }];
                        
                        NSData *imageData=UIImageJPEGRepresentation(image,0.83);
                        [strongSelf.qiNiumanager putData:imageData key:[NSString stringWithFormat:@"%@%@.jpg",imagefileNameKey,[strongSelf generateRandomFileName]] token:strongSelf.qiniuToken complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
                            
                            if (info.error==nil) {
                                [images addObject:key];
                                
                            }else{
                                
                            }
                            dispatch_group_leave(group);
                        } option:uploadOption];
                        
                        
                    });
                }
                
                dispatch_group_notify(group, queue, ^{//所有图片上传完成

                    imgPathsBlock(images);
                    
                });
                
            }

- (void)uploadOneImageWith:(UIImage *)img imagefileNameKey:(NSString*)imagefileNameKey  imagePostKeyName:(NSString*)imagePostKeyName postURL:(NSString*)postURLStr parameters:(NSDictionary*)parameters  notificationName:(NSString*)notificationName{
    self.releaseSuccessedNotificationName = notificationName;
    self.imageCount = 1;
    self.imageUploadPerscentArr = [NSMutableArray arrayWithCapacity:self.imageCount];
    for (NSInteger i=0; i<self.imageCount; i++) {
        [self.imageUploadPerscentArr addObject:@(0.0)];
    }
    
    __block NSMutableDictionary *mutableParameters = [NSMutableDictionary dictionaryWithDictionary:parameters];
    __block NSMutableArray *images = [NSMutableArray array];
    
    dispatch_group_t group = dispatch_group_create();
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    WEAK_SELF(weakSelf)
    
    dispatch_group_enter(group);
    
    dispatch_async(queue, ^{
        STRONG_SELF(strongSelf)
        
        QNUploadOption *uploadOption = [[QNUploadOption alloc]initWithProgressHandler:^(NSString *key, float percent) {
            dispatch_async(dispatch_get_main_queue(), ^{
                [strongSelf.imageUploadPerscentArr replaceObjectAtIndex:0 withObject:@(percent/strongSelf.imageCount*100)];
                CGFloat percent = 0.0;
                for (NSNumber *percentValue in strongSelf.imageUploadPerscentArr) {
                    percent += percentValue.floatValue;
                }
                [[UploadProgressView sharedInstance] showWithTitle:[NSString stringWithFormat:@"图片%.0f%%",percent] progress:percent];
            });
            
        }];
        
        NSData *imageData=UIImageJPEGRepresentation(img,0.83);
        [strongSelf.qiNiumanager putData:imageData key:[NSString stringWithFormat:@"%@%@.jpg",imagefileNameKey,[strongSelf generateRandomFileName]] token:strongSelf.qiniuToken complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
            dispatch_group_leave(group);
            if (info.error==nil) {
                [images addObject:key];
                
            }else{
                
            }
            
        } option:uploadOption];
        
        
    });
    
    dispatch_group_notify(group, queue, ^{//所有图片上传完成
        
        if (images.count!= 1) {
            [[UploadProgressView sharedInstance] hideWithTitle:@"失败！"];
            return ;
        }

        [mutableParameters setObject:images.firstObject forKey:imagePostKeyName];
        STRONG_SELF(strongSelf)
        LoginDataManager *loginDataManager = [[ProjectMediator sharedInstance] getLoginDataManagerInLoginAndRegisterLib];
        [HJNetwork setHeadr:@{@"Accept":@"application/vnd.zhb.v1+json"}];
        [HJNetwork setHeadr:@{@"Authorization":[NSString stringWithFormat:@"Bearer %@",loginDataManager.currentLoginData.token]}];
        [HJNetwork HTTPWithMethod:HJRequestMethodPOST url:postURLStr parameters:mutableParameters cachePolicy:HJCachePolicyIgnoreCache callback:^(id responseObject, BOOL isCache, NSError *error) {
            
            if (error==nil) {
                
                [[UploadProgressView sharedInstance] hideWithTitle:@"成功！"];
                
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    
                    [[NSNotificationCenter defaultCenter] postNotificationName:strongSelf.releaseSuccessedNotificationName object:images.firstObject];
                    
                });
            }else{
                [[UploadProgressView sharedInstance] hideWithTitle:@"失败！"];
                NSLog(@"发布失败");
                
            }
        }];
    });
}

- (void)uploadWithOutUseQINIUForImage:(UIImage *)image imagePostKeyName:(NSString*)name fileName:(NSString*)fileName  postURL:(NSString*)postURLStr parameters:(NSDictionary*)parameters notificationName:(NSString*)notificationName{
    self.releaseSuccessedNotificationName = notificationName;
    
    NSString *mimeType = @"png";
    if ([fileName hasSuffix:@"JPG"]||[fileName hasSuffix:@"jpg"]||[fileName hasSuffix:@"jpeg"]||[fileName hasSuffix:@"JPEG"]) {
        mimeType = @"jpeg";
    }
    LoginData *loginData = [[LoginDataManager sharedManager]currentLoginData];
    [HJNetwork setHeadr:@{@"token":loginData.token}];
    WEAK_SELF(weakSelf)
    [HJNetwork uploadImageURL:postURLStr parameters:parameters images:@[image] name:name fileName:fileName mimeType:mimeType progress:^(NSProgress *progress) {
        NSLog(@"progress.fractionCompleted:%f",progress.fractionCompleted);
        [[UploadProgressView sharedInstance] showWithTitle:[NSString stringWithFormat:@"图片%.0f%%",progress.fractionCompleted] progress:progress.fractionCompleted];
    } callback:^(id responseObject, BOOL isCache, NSError *error) {
        if (!error) {
        [[UploadProgressView sharedInstance] hideWithTitle:@"上传成功！"];
            STRONG_SELF(strongSelf)
            [[NSNotificationCenter defaultCenter] postNotificationName:strongSelf.releaseSuccessedNotificationName object:responseObject];
            
        }else{
            [[UploadProgressView sharedInstance] hideWithTitle:@"上传失败！"];
        }
        
    }];
}
-(QNUploadManager*)qiNiumanager{
    if (!_qiNiumanager) {
        _qiNiumanager = [[QNUploadManager alloc]init];
    }
    return _qiNiumanager;
}
//产生随机30个字符串+时间戳作为文件ID
- (NSString *)generateRandomFileName
{
    
    NSString *sourceStr = @"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    NSMutableString *resultStr = [[NSMutableString alloc] init];
    NSUInteger kNumber = sourceStr.length;
    for (NSUInteger i = 0; i < 30; i++)
    {
        NSInteger index = arc4random() % kNumber;
        NSString *oneStr = [sourceStr substringWithRange:NSMakeRange(index, 1)];
        [resultStr appendString:oneStr];
    }
    NSDate* dat = [NSDate dateWithTimeIntervalSinceNow:0];
    
    NSTimeInterval a=[dat timeIntervalSince1970];
    return [NSString stringWithFormat:@"%@%.0f",resultStr,a];
}
@end
